<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.json.JSONObject"%>
<%@page import="db.ReadDAO"%>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ReadDAO msgDao = (ReadDAO)ctx.getBean("ReadDAO");
	
	String tid_str = request.getParameter("tid");
	Integer tid_int = Integer.parseInt(tid_str);
	
	if(tid_int != 0){
		session.setAttribute("tid",tid_int);
		
		Integer uid = (Integer)session.getAttribute("id");
		
		List where = new ArrayList();
		where.add(new Object[]{"eq","teamId",tid_int});
		where.add(new Object[]{"eq","userId",uid});
		where.add(new Object[]{"eq","isRead",0});
		
		Map map = msgDao.getRead(0, 0, 
				new String[][]{new String[]{"desc","date"}}, 
				where, 
				new String[][]{new String[]{"","id"}}, 
				null);
		
		JSONObject json = new JSONObject();
		json.put("map",map);
		out.print(json.toString());
	}else{
		session.removeAttribute("tid");
		JSONObject json = new JSONObject();
		out.print(json.toString());
	}
%>